<?php
/**
*Create Date: 08/20/2011 11:08:01
\*Author: Jossue O. Rodriguez C.   $LastChangedRevision:$
*/

?>
<?php
if($name)
{
?>
<form name="<?php echo $name; ?>" id="<?php echo $name; ?>" method='POST' action='<?php echo $action; ?>'>
<?php
}
?>
	<table cellspacing="0" cellpadding="0" border="0">
		<tbody>
			<?php
			
			foreach ($prototype as $campo => $value) {
				if($sufix != ""){
					$nombreCampo = $prefix . $campo . "[]";
				}else{
					$nombreCampo = $prefix . $campo . $sufix;
				}
				
				$idCampo = $prefix . $campo . $sufix;
				$attrs = (isset($html[$campo]))? $this->genAttribs($html[$campo], false) : null;
			?>
			<tr>
				<th valign="top" class="form-label"><?php echo $legents[$campo]?>:</th>
				<td>
					<?php 
					if(isset($types[$campo])){
						

						switch($types[$campo]){
							
							case "label":
								?>
								<span><?php echo $value; ?></span>
								<?php
							break;
							
							
							
							case "hidden":
								?>
								<input type="hidden" name="<?php echo $nombreCampo?>" value="<?php echo $value?>"  <?php echo $attrs; ?>/>
								<?php
							break;
							
							case "textarea":
								?>
								<textarea name="<?php echo $nombreCampo?>" <?php echo $attrs; ?>><?php echo $value; ?></textarea>
								<?php
							break;
							
							case "radio":
								if(isset($sources[$campo]) && $sources[$campo] instanceof AbstractBaseDAO )
								{
									$dao = $sources[$campo];
								?>
								
									<?php
									while ($row = $dao->get()) {
										$selected = ($row[$dao->selectID] == $value)? "checked" : "";
										?>
										<label for="" class="">
											<?php echo $row[$dao->selectName]?>
											<input type="radio" name="<?php echo $nombreCampo?>" value="<?php echo $row[$dao->selectID]?>" <?php echo $attrs; ?> />
										</label>
										<?php
									}
									?>

								<?php
								}
							break;
							
							case "check":
								if(isset($sources[$campo]) && $sources[$campo] instanceof AbstractBaseDAO )
								{
									$dao = $sources[$campo];
								?>
								
									<?php
									while ($row = $dao->get()) {
										$selected = ($row[$dao->selectID] == $value)? "checked" : "";
										?>
										<label for="" class="">
											<?php echo $row[$dao->selectName]?>
											<input type="checkbox" name="<?php echo $nombreCampo?>[]" value="<?php echo $row[$dao->selectID]?>" <?php echo $attrs; ?> />
										</label>
										<?php
									}
									?>

								<?php
								}
							break;
							
							case "select":
								if(isset($sources[$campo]) && $sources[$campo] instanceof AbstractBaseDAO )
								{
									$dao = $sources[$campo];
								?>
								<select name="<?php echo $nombreCampo?>" id="<?php echo $idCampo?>" <?php echo $attrs; ?>>
									<option></option>
									<?php
									while ($row = $dao->get()) {
										$selected = ($row[$dao->selectID] == $value)? "selected" : "";
										?>
										<option value="<?php echo $row[$dao->selectID]?>" <?php echo $selected; ?>>
											<?php echo $row[$dao->selectName]?>
										</option>
										<?php
									}
									?>
								</select>
								<?php
								}
							break;
							
							case "search_select":
								
								?>
								<input id="<?php echo $idCampo?>" name="<?php echo $nombreCampo?>" type="hidden" value="<?php echo $value;?>" <?php echo $attrs; ?>>
								<a href="javascript:void(0)" onclick="rvm_finder.open('dialog-<?php echo $idCampo?>')">search</a>
								<div id="result-<?php echo $idCampo?>"></div>
								<div id="dialog-<?php echo $idCampo?>" style="display: none"></div>
								<script>
									 
									 <?php 
									 	
								 		$p = $searchParams[$campo];
										$p["dialog"]= 'dialog-' . $idCampo;
										$p["showDest"]= 'result-' . $idCampo;
										
								 		$rf = $showParams[$campo]["returnField"];
										unset($showParams[$campo]["returnField"]);
										
									 ?>
									 rvm_finder.add('dialog-<?php echo $idCampo?>', '', '<?php echo $idCampo?>', '<?php echo $searchAction[$campo]; ?>','<?php echo http_build_query($p, '', '&'); ?>', '<?php echo $showAction[$campo]; ?>','<?php echo json_encode($showParams[$campo]); ?>', '<?php echo $rf; ?>',"<?php echo $value;?>");
								</script>
								<?php
								
							break;
							
							case "multiple_select":
								
								?>
								
								
								<div id="multiple-<?php echo $idCampo?>"></div>
								
								<script>
									 new rvm_multiple('multiple-<?php echo $nombreCampo?>', '<?php echo $searchAction[$campo]; ?>', '<?php echo http_build_query($searchParams[$campo], '', '&'); ?>', '<?php echo showMessage('Add');?>');
								</script>
								<?php
								
							break;
							
							
							
							case "date":
								?>
								<input name="<?php echo $nombreCampo?>" id="<?php echo $idCampo?>" type="text"  value="<?php echo $value;?>" <?php echo $attrs; ?>>
								<script>
									$j( "#<?php echo $idCampo; ?>" ).datepicker({
										 dateFormat: 'dd-mm-yy'
									});
								</script>
								<?php
							break;
							
							default:
								?>
								<input name="<?php echo $nombreCampo?>" type="text" class="inp-form-error" value="<?php echo $value;?>">
								<?php
						}
							
						
					}else{
						?>
						<input name="<?php echo $nombreCampo?>" type="text" value="<?php echo $value;?>" <?php echo $attrs; ?>>
						<?php
						}
					?>
				</td>
			</tr>
			<?php 
			}
			?>
		</tbody>
	</table>
	<?php
	if(is_array($params)){
		foreach ($params as $paramName => $value) {
			if($value != ""){
				?>
				<input type="hidden" name="<?php echo $paramName; ?>" value="<?php echo $value?>" />
				<?php
			}
		}
	}
	?>
<?php
if($name)
{
?>
</form>
<br />
<a href="javascript: void(0)" onclick="send_form('<?php echo $name; ?>', '<?php echo $resultID; ?>', '<?php echo $actionDO; ?>', '')">Ok</a>
<?php
}
?>